// pages/order/order.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data:[
      
    ],
    page:1,
    limit:20
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let uid = wx.getStorageSync("uid");
    wx.showLoading({
        title: '加载中',
    })
    wx.request({
      url: 'https://www.shumutou.com/api/index/record',
      method:'post',
      data: {
        uid: uid,
        page:that.data.page,
        limit:that.data.limit
      },
      success:(res)=>{
        wx.hideLoading()
        console.log(res)
        this.setData({
          data:res.data.data,
          count:res.count
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var _this = this
    var data = _this.data.data
    var page = _this.data.page;
    var limit = _this.data.limit;
    var count = _this.data.count;
    let uid = wx.getStorageSync("uid");
    if((count - (page * limit)) > 0){
        wx.showToast({  
            title: '没有更多了',  
            icon: 'error',  
            duration: 2000  
          })
          return;
    }
    page++;
    wx.showLoading({
        title: '加载中',
    })
    wx.request({
        url: 'https://www.shumutou.com/api/index/record',
        method:'post',
        data: {
          uid: uid,
          page:page,
          limit:limit
        },
        success:(res)=>{
            wx.hideLoading()
          var newdata = res.data.data;
          for(var i=0;i<newdata.length;i++){
            data.push(newdata[i])
          }
          _this.setData({
            data:data
          })
        }
      })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})